home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / grphme10.zip / TECHNICL.DOC < prev    next >
Text File  |  1992-11-15  |  8KB  |  147 lines

  1.  
  2.      Well, if you want to get into the nitty-gritty of how
  3.      Graph-Me! works, read on.  If not, skip over this and into
  4.      the next article.  Be sure to read GRAPHME.DOC.
  5.  
  6.  
  7. THE BASICS:
  8.      The technology behind Graph-Me!'s equation interpreter is
  9.      called Recursive Descent Parsing.  What that means is that a
  10.      small ammount of code is used over and over again
  11.      (recursive), at seperate levels (descent), until the
  12.      equation is parsed (taken from human language and put into
  13.      machine language).  I do this by breaking the entire line
  14.      into 'tokens', and then dividing these tokens into four
  15.      major groups, which I quite generically call 'level0'
  16.      through 'level3'.  The schematic of this break-up follows.
  17.  
  18.      level0:
  19.           level1 {+, -} level1 ... EOL,')'
  20.      level1:
  21.           level2 {*,/,%,^} level2 ...
  22.      level2:
  23.           {{sin, cos, ln, exp ...} level2 , level3}
  24.      level3:
  25.           {{-}<Number>, '('level0')'}
  26.  
  27.      (In understanding this schematic, items in curly brackets
  28.      ('{','}') and seperated by ',' denote options, one or the
  29.      other.  'level1' denotes any level1 expression should be
  30.      inserted at that place, etc.)
  31.  
  32.      As you can see, the 'recursive' part of the algorithm comes
  33.      from going all the way through the heirarchy and
  34.      encounterring an open parentheses, which forces us back to
  35.      the top of the hierarchy (level0).
  36.  
  37.      Using this structure as a basis, it is easy to see that the
  38.      basic rules of arithmetic are observed -- the hierarchy and
  39.      the parentheses override, everything else left-to-right.
  40.  
  41.      Some small factors, however, are worth noting because they
  42.      are not specified in the arithmetic rules.  For instance,
  43.      the modulus and power operators (%,^) are of the same level
  44.      as the multiplication and divide (*,/).  This means that a
  45.      line of the sort '3*2^4*5' is read as '((3*2)^4)*5', because
  46.      it is simply translated left-to-right.  Some people find
  47.      this intuitive while others find it counter-intuitive.  I
  48.      would like feedback on this so that later versions are as
  49.      close to a 'standard' as possible.  (Some people see the
  50.      line as '3*(2^4)*5', rather than what it actually comes out
  51.      to be.)  This area is further blurred by the lt and gt
  52.      (greatest integer less than and least integer greater than)
  53.      operators, which are so seldom used that they have *no*
  54.      intuitiveness at all -- at least not to me.
  55.      All of this is done before any graphing starts.  The result
  56.      of this tokenization is a compact, yet unique, array of
  57.      tokens which define the equation you put in.
  58.  
  59. PLOTTING:
  60.      Once we have done a pre-calculation on the input line (it is
  61.      in an array of tokens rather than a cryptic string), all
  62.      that is left to do is put a bit of form to it.  Graph-Me!
  63.      works by setting the first independent variable as a
  64.      constant, and then varying the second independent variable
  65.      from its minimum value to its maximum value.  Straight lines
  66.      are drawn between each data point to eliminate horizontal
  67.      gaps and in order to allow less-than-screen-accuracy images
  68.      to look smooth.  Before each line is drawn, it is transfered
  69.      from 3-d space to screen-space.
  70.  
  71.      Currently, each line is independant of each other line; no
  72.      value is used twice.  This can be rather inefficient,
  73.      especially at low accuracy settings (high numbers, > 10). 
  74.      In the near future I hope to add a 'Matrix' option which
  75.      will allow a faster on-screen representation by reducing the
  76.      number of calculations taken to the number of vertices which
  77.      exist on the graph, within the bounds.  In other words,
  78.      whereas now everything is nice and smooth between vertices,
  79.      the 'Matrix' option will reduce the accuracy until graph
  80.      consists of straight lines, from vertice to vertice.  Also,
  81.      the 'Matrix' option will eliminate 'double-calculating' of
  82.      data points by keeping points in memory longer.  This should
  83.      increase the speed tenfold at the least, giving a very rough
  84.      sketch of the layout of the graph and almost-realtime
  85.      rotation.  I also hope to develope a proprietary method for
  86.      saving images in this form so that total recalculation is
  87.      not necessary.
  88.  
  89.      Back to the present, Graph-Me! writes this information to
  90.      screen, then forgets it.  This is good, considerring a very
  91.      low resolution image contains 1.2 Mb of information 
  92.      (640x480x4 bytes per data point), and a higher res. image,
  93.      or one in which the x-y plane is not parallel to the screen,
  94.      quickly would eat up the memory.  I have briefly considerred
  95.      being able to do a total save of this (so that a full-
  96.      quality image could be brought up within minutes), but
  97.      decided against it, since few of us have ten Megs or so of
  98.      free disk space.  If there is an interrest, I'll work on it,
  99.      but I foresee no demand at present.
  100.  
  101.      But, since Graph-Me! simply forgets all it has worked so
  102.      hard to calculate, the slightest twist, turn, or zoom
  103.      requires a full redraw of the image.  Beware this!  There is
  104.      nothing worse than waiting fifteen minutes for an image to
  105.      be drawn, only to find that it needs just a smidgen more
  106.      rotation this way or that ...
  107. TIPS:
  108.      Well, I suppose the last sentence in the preceeding section
  109.      is the first tip I can give you.  If getting a nice print-
  110.      out of just the right angle of a graph is important to you,
  111.      *Preview the Graph First* by setting the accuracy to ten or
  112.      so, then put it back down to two or three for the final
  113.      product.
  114.  
  115.      Secondly, an accuracy of one is often quite wasteful.  The
  116.      'one' refers to, if the x-y plane were put parallel to the
  117.      screen, one pixel straight down from the center of the
  118.      screen.  It doesn't take a lot of rotation before an
  119.      accuracy rating of 'two' gives you pixel-accuracy, and just
  120.      a bit more before a rating of *three* gives you pixel
  121.      accuracy.  Look at it for yourself.  If the lines seem to
  122.      wiggle back and forth a lot (this is due to round-off error
  123.      in your computer's CPU), increase the accuracy rating a bit. 
  124.      (Remember, a higher accuracy rating means a less accurate
  125.      depiction).  If your 'sin' wave looks like a bunch of
  126.      straight lines, decrease the rating a few pixels until it
  127.      looks right.  You have to eye it for now, until I get the
  128.      code in place to put it at pixel accuracy automatically.
  129.  
  130.      Third, if a formula seems to generate a strange graph, put
  131.      the equation through the calculator (substituting actual
  132.      values for the variables, of course) and see if my
  133.      calculations routine is doing what you expect.  Two notable
  134.      possibilities for error are listed above, in the general
  135.      description of the parser.
  136.  
  137.      Finally, a faster computer makes all the difference in the
  138.      world.  This program is extremely calculation dependant, and
  139.      therefore would benifit *greatly* from a faster cpu.  I
  140.      currently do not have support for the fpu (80x87), but that
  141.      should be coming within the first few versions.  If you find
  142.      that a simple graph takes hours to graph, move on up past
  143.      the 286 line and into something meatier, ('486 highly
  144.      recommended) or, if your funds are not quite equal to those
  145.      of Ross Perot, sneak this program onto a friend's fast
  146.      computer and graph away!
  147.